<!--
 * @Author: chenhaoran
 * @Date: 2024-08-08 15:01:42
 * @LastEditors: chenhaoran
 * @LastEditTime: 2024-08-08 18:06:02
-->
<template>
  <div class="chart-card">
    <el-row :gutter="20">
      <el-col :span="18">
        <el-card>
          <div class="chart" id="line-chart"></div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card>
          <div class="chart" id="pie-chart"></div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
// import VChart from 'echarts'
// 引入 echarts 核心模块，核心模块提供了 echarts 使用必须要的接口。
import * as echarts from 'echarts/core';
import { use, graphic } from 'echarts/core';
// 引入折线图图表，图表后缀都为 Chart
/*
 * 如何查看引入图表类型的名称
 * node_modules\echarts\dist\echarts.js -->function --BUILTIN_CHARTS_MAP 
*/
import { LineChart, PieChart } from 'echarts/charts';
// 引入标题，提示框，直角坐标系，数据集，内置数据转换器组件，组件后缀都为 Component
/*
 * 如何查看引入图表类型的名称
 * node_modules\echarts\dist\echarts.js -->function --BUITIN_COMPONENTS_MAP 
*/
import {
  TitleComponent,
  TooltipComponent,
  GridComponent,
  DatasetComponent,
  TransformComponent,
  LegendComponent 
} from 'echarts/components';
// 标签自动布局、全局过渡动画等特性
import { LabelLayout, UniversalTransition } from 'echarts/features';
// 引入 Canvas 渲染器，注意引入 CanvasRenderer 或者 SVGRenderer 是必须的一步
import { CanvasRenderer } from 'echarts/renderers';

// 注册必须的组件
use([
  TitleComponent,
  TooltipComponent,
  GridComponent,
  DatasetComponent,
  TransformComponent,
  LineChart,
  PieChart,
  LabelLayout,
  UniversalTransition,
  CanvasRenderer,
  LegendComponent 
]);

onMounted(() => {
  // 接下来的使用就跟之前一样，初始化图表，设置配置项
  var lineChart = echarts.init(document.getElementById('line-chart'));
  lineChart.setOption({
    title: {
      text: '订单动态',
      subtext: '最近一周订单状态，包括订单成交量和订单退货量'
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
    },
    yAxis: {
      type: 'value',
    },
    grid: {
      top: '16%',
      left: '1%',
      right: '3%',
      bottom: '2%',
      containLabel: true,
    },
    color: ['#009688', '#f44336'],
    series: [
      {
        type: 'line',
        areaStyle: {
          color: new graphic.LinearGradient(0, 0, 0, 1, [
            {
              offset: 0,
              color: 'rgba(0, 150, 136,0.8)',
            },
            {
              offset: 1,
              color: 'rgba(0, 150, 136,0.2)',
            },
          ]),
        },
        smooth: true,
        data: [120, 132, 301, 134, 90, 230, 210],
      },
      {
        type: 'line',
        smooth: true,
        data: [220, 122, 191, 234, 190, 130, 310],
      },
    ],
  });
  var pieChart = echarts.init(document.getElementById('pie-chart'));
  pieChart.setOption({
    title: {
      text: '品类分布',
      subtext: '最近一个月销售商品的品类情况',
    },
    legend: {
        bottom: '1%',
        left: 'center',
    },
    color: ['#3f51b5', '#009688', '#f44336', '#00bcd4', '#1ABC9C'],
    series: [
        {
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: false,
            itemStyle: {
                borderRadius: 10,
                borderColor: '#fff',
                borderWidth: 2,
            },
            data: [
                { value: 1048, name: '数码' },
                { value: 735, name: '食品' },
                { value: 580, name: '母婴' },
                { value: 484, name: '家电' },
                { value: 300, name: '运动' },
            ],
        },
    ],
})
})



</script>
<style scoped>
.chart-card {
  margin: 20px 0;
}
.chart {
  width: 100%;
  height: 400px;
}
</style>